home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / raw_nl1 / mkrawidx.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  4KB  |  169 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <ext.h>
  6. #include <tos.h>
  7. #include <portab.h>
  8. #include <defines.h>
  9.  
  10. #define VERSION    "0.01"
  11.  
  12. static uword parse_list(FILE *fp,ubyte *src,uword nlnumber,uword defzone,uword pointlist);
  13. static void new_entry(FILE *out,ulong offset,uword zone,uword net,uword node,uword point);
  14.  
  15. HEADER         header;
  16. NLHEADER    nlheader;
  17. ENTRY         entry;
  18.  
  19. int main(int argc,char *argv[])
  20. {    int i;
  21.     FILE    *fp;
  22.     --argc;
  23.  
  24.     if (argc<1)
  25.     {    fprintf(stderr,"MKRAWIDX V"VERSION"   Nodelist-Utility (Demo)     (c) Stephan Slabihoud 1995\n\n\n");
  26.  
  27.         fprintf(stderr,"Usage: mkrawidx <lst1> [<lst2> [...]]\n");
  28.         getch();
  29.         exit(2);
  30.     }
  31.     printf("MKRAWIDX V"VERSION"   Nodelist-Utility (Demo)     (c) Stephan Slabihoud 1995\n\n\n");
  32.  
  33. /*
  34. ** Open output file
  35. */
  36.  
  37.     fp=fopen("NODELIST.RDX","wb");
  38.  
  39. /*
  40. ** Create header. Note: header.version is 0x0001 !
  41. */
  42.  
  43.     header.version=0x0001;
  44.     time(&(time_t)header.datetime);
  45.     header.nodelists=argc;                            /* number of nodelists */
  46.     header.flag=0;                                            /* output is unsorted     */
  47.     fwrite(&header,sizeof(HEADER),1,fp);
  48.  
  49. /*
  50. ** Now write all Nodelist-Header...
  51. */
  52.  
  53.     for (i=1; i<=header.nodelists; i++)
  54.     {    nlheader.type=0;                                    /* only nodelists in that demo */
  55.         nlheader.day=0;                                        /* Not yet implemented                 */
  56.         *nlheader.network='\0';                        /* Not yet implemented                 */
  57.         strcpy(nlheader.file,argv[i]);        /* filename                                         */
  58.         fwrite(&nlheader,sizeof(NLHEADER),1,fp);
  59.     }
  60.  
  61. /*
  62. ** ...and all nodelist entries
  63. */
  64.  
  65.     for (i=0; i<header.nodelists; i++)
  66.         parse_list(fp,argv[i+1],i,0,FALSE);
  67.  
  68.     fclose(fp);
  69.     return(0);
  70. }
  71.  
  72. /*
  73. ** defzone is not yet used. This parameter is neccessary when
  74. **         including a 3d pointlist.
  75. ** pointlist must be TRUE when parsing a pointlist and otherwise FALSE
  76. */
  77.  
  78. static uword parse_list(FILE *fp,ubyte *src,uword nlnumber,uword defzone,uword pointlist)
  79. {    uword    zone=0,net=0,node=0,point=0;
  80.     ulong    counter=0,offset=0;
  81.     FILE    *in;
  82.     ubyte    line[256],*pointer,*pointer2;
  83.  
  84.     entry.nodelist=nlnumber;
  85.  
  86.     in    = fopen(src,"rb");
  87.     setvbuf(in ,NULL,_IOFBF,32768U);
  88.     printf("\nConverting... %lu\r",counter);
  89.  
  90.     if (pointlist)
  91.         zone=defzone;
  92.  
  93.     fgets(line,256,in);
  94.     while (!feof(in))
  95.     {    if (*line!=';')
  96.         {    
  97.             if (!strnicmp(line,"zone",4))
  98.             {    zone=atoi(strchr(line,',')+1);
  99.                 node=point=0;
  100.                 net=zone;
  101.                 new_entry(fp,offset,zone,net,node,point);
  102.             }
  103.             else if (!strnicmp(line,"region",6))
  104.             {    net=atoi(strchr(line,',')+1);
  105.                 node=point=0;
  106.                 if (!pointlist)
  107.                     new_entry(fp,offset,zone,net,node,point);
  108.             }
  109.             else if (!strnicmp(line,"host",4))
  110.             {    pointer=strchr(line,',');
  111.                 if (pointlist)
  112.                 {    pointer2=strchr(pointer+1,',');
  113.                     net=atoi(pointer2+1);
  114.                     pointer2=strchr(pointer2+1,'/');
  115.                     if (pointer2==NULL)
  116.                     {    net=atoi(line+5);    /* ERROR: use Fakenet */
  117.                         node=0;
  118.                     }
  119.                     else
  120.                         node=atoi(pointer2+1);
  121.                 }
  122.                 else
  123.                 {    net=atoi(pointer+1);
  124.                 }
  125.                 point=0;
  126.                 new_entry(fp,offset,zone,net,node,point);
  127.             }
  128.             else if ( *line==','                                        ||
  129.                               strnicmp(line,"hub",3)==0            ||
  130.                               strnicmp(line,"down",4)==0        ||
  131.                               strnicmp(line,"hold",4)==0        ||
  132.                               strnicmp(line,"pvt",3)==0 )
  133.             {    pointer=strchr(line,',');
  134.                 if (pointlist)
  135.                 {    point=atoi(pointer+1);
  136.                     if (!node)
  137.                     {    node=point;
  138.                         point=0;
  139.                     }
  140.                 }
  141.                 else
  142.                 {    node=atoi(pointer+1);
  143.                 }
  144.                 new_entry(fp,offset,zone,net,node,point);
  145.             }
  146.         }
  147.         counter++;
  148.         if (!(counter & 0xff))
  149.             printf("Converting... %lu\r",counter);
  150.  
  151.         offset=ftell(in);
  152.         fgets(line,256,in);
  153.     }
  154.     printf("Converted.... %lu names\n\n",counter);
  155.     fclose(in);
  156.     return(0);
  157. }
  158.  
  159. static void new_entry(FILE *out,ulong offset,uword zone,uword net,uword node,uword point)
  160. {    entry.zone=zone;
  161.     entry.net=net;
  162.     entry.node=node;
  163.     entry.point=point;
  164.     entry.offset=offset;
  165.     entry.f_flags=0;                                        /* Not yet implemented */
  166.     entry.m_flags=0;                                        /* Not yet implemented */
  167.     fwrite(&entry,sizeof(ENTRY),1,out);
  168. }
  169.